package org.zpmis.api.business;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.stereotype.Service;
import org.zpmis.common.base.AdminLoginUser;
import org.zpmis.common.base.AppletsLoginUser;
import org.zpmis.common.base.BaseWebService;
import org.zpmis.common.enums.SequenceEnum;
import org.zpmis.common.exception.BusinessException;
import org.zpmis.common.result.ResultCode;
import org.zpmis.common.utils.StringUtil;
import org.zpmis.domain.company.model.Company;
import org.zpmis.domain.company.service.CompanyService;
import org.zpmis.domain.contract.enums.ContractEnum;
import org.zpmis.domain.contract.model.Contract;
import org.zpmis.domain.order.enums.OrderDetailEnum;
import org.zpmis.domain.order.enums.OrderEnum;
import org.zpmis.domain.order.model.Order;
import org.zpmis.domain.order.model.OrderDetail;
import org.zpmis.domain.order.qo.*;
import org.zpmis.domain.order.service.OrderDetailService;
import org.zpmis.domain.order.service.OrderService;
import org.zpmis.domain.order.vo.OrderDetailVo;
import org.zpmis.domain.order.vo.OrderListVo;
import org.zpmis.domain.sequence.service.SequenceService;
import tk.mybatis.mapper.entity.Condition;
import tk.mybatis.mapper.entity.Example;

import java.math.BigDecimal;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * Created with CodeGenerator
 * Description:
 * @author  Yang
 * Date: 2021-6-2
 * Time: 14:51:37
 */
@Service
@Slf4j
public class OrderWebService extends BaseWebService {
     @Reference
     private OrderService orderService;

     @Reference
     private OrderDetailService orderDetailService;

     @Reference
     private SequenceService sequenceService;

     @Reference
     private CompanyService companyService;


     /**
      * 申请订单
      * @param applyOrderQo
      */
     public void applyOrder(ApplyOrderQo applyOrderQo) throws Exception{
          //订单的企业id
          Long companyId = applyOrderQo.getCompanyId();
          if(companyId == null){
               throw new BusinessException(ResultCode.USER_NOT_LOGIN);
          }
          orderService.save(
          Order.builder()
                  .orderNumber(sequenceService.getSequenceNum(SequenceEnum.ORDER))
                  .applyTime(Instant.now().toEpochMilli())
                  .companyId(companyId)
                  .applyCompanyType(applyOrderQo.getApplyCompanyType())
                  .applyServiceType(applyOrderQo.getApplyServiceType())
                  .applyNumber(applyOrderQo.getApplyNumber())
                  .applyType(applyOrderQo.getApplyType())
                  .applySpecs(applyOrderQo.getApplySpecs())
                  .craftMaterial(applyOrderQo.getCraftMaterial())
                  //.unitPrice(StringUtil.isEmpty(applyOrderQo.getUnitPrice()) ? null : new BigDecimal(applyOrderQo.getUnitPrice()).setScale(4))
                  //.totalPrice(StringUtil.isEmpty(applyOrderQo.getTotalPrice()) ? null : new BigDecimal(applyOrderQo.getTotalPrice()).setScale(4))
                  .invoiceType(applyOrderQo.getInvoiceType())
                  .invoiceCompanyName(applyOrderQo.getInvoiceCompanyName())
                  .invoiceTaxpayerIdentiNumber(applyOrderQo.getInvoiceTaxpayerIdentiNumber())
                  .bankName(applyOrderQo.getBankName())
                  .bankAccountName(applyOrderQo.getBankAccountName())
                  .bankAccount(applyOrderQo.getBankAccount())
                  .invoiceAddress(applyOrderQo.getInvoiceAddress())
                  .invoiceMobile(applyOrderQo.getInvoiceMobile())
                  .consignee(applyOrderQo.getConsignee())
                  .takeDeliveryAdress(applyOrderQo.getTakeDeliveryAdress())
                  .taskDeliveryMobile(applyOrderQo.getTaskDeliveryMobile())
                  .status(OrderEnum.INIT_STATUS.code())
                  .collectionStatus(OrderEnum.UNCOLLECTED_STATUS.code())
                  .isDeleted(OrderEnum.NOT_DELETE.code())
                  .createTime(Instant.now().toEpochMilli())
                  .updateTime(Instant.now().toEpochMilli())
                  .shareAttachment(applyOrderQo.getShareAttachment())
                  .attachmentImage(applyOrderQo.getAttachmentImage())
                  .receiptAttachment(applyOrderQo.getReceiptAttachment())
                  .agentCompanyId(applyOrderQo.getAgentCompanyId())//代理的企业id
                  .build()
          );
     }

     /**
      * 后台新增订单
      * @param applyOrderQo
      */
     public void addOrder(ApplyOrderQo applyOrderQo) throws Exception{
          //获取当前登录用户的企业id
          Long companyId = applyOrderQo.getCompanyId();
          if(companyId == null){
               throw new BusinessException(ResultCode.USER_NOT_LOGIN);
          }
          orderService.save(
                  Order.builder()
                          .orderNumber(sequenceService.getSequenceNum(SequenceEnum.ORDER))
                          .applyTime(Instant.now().toEpochMilli())
                          .companyId(companyId)
                          .applyCompanyType(applyOrderQo.getApplyCompanyType())
                          .applyServiceType(applyOrderQo.getApplyServiceType())
                          .applyNumber(applyOrderQo.getApplyNumber())
                          .applyType(applyOrderQo.getApplyType())
                          .applySpecs(applyOrderQo.getApplySpecs())
                          .craftMaterial(applyOrderQo.getCraftMaterial())
                          .unitPrice(StringUtil.isEmpty(applyOrderQo.getUnitPrice()) ? null : new BigDecimal(applyOrderQo.getUnitPrice()).setScale(4))
                          .totalPrice(StringUtil.isEmpty(applyOrderQo.getTotalPrice()) ? null : new BigDecimal(applyOrderQo.getTotalPrice()).setScale(4))
                          .invoiceType(applyOrderQo.getInvoiceType())
                          .invoiceCompanyName(applyOrderQo.getInvoiceCompanyName())
                          .invoiceTaxpayerIdentiNumber(applyOrderQo.getInvoiceTaxpayerIdentiNumber())
                          .bankName(applyOrderQo.getBankName())
                          .bankAccountName(applyOrderQo.getBankAccountName())
                          .bankAccount(applyOrderQo.getBankAccount())
                          .invoiceAddress(applyOrderQo.getInvoiceAddress())
                          .invoiceMobile(applyOrderQo.getInvoiceMobile())
                          .consignee(applyOrderQo.getConsignee())
                          .takeDeliveryAdress(applyOrderQo.getTakeDeliveryAdress())
                          .taskDeliveryMobile(applyOrderQo.getTaskDeliveryMobile())
                          .status(OrderEnum.INIT_STATUS.code())
                          .collectionStatus(OrderEnum.UNCOLLECTED_STATUS.code())
                          .isDeleted(OrderEnum.NOT_DELETE.code())
                          .createTime(Instant.now().toEpochMilli())
                          .updateTime(Instant.now().toEpochMilli())
                          .shareAttachment(applyOrderQo.getShareAttachment())
                          .attachmentImage(applyOrderQo.getAttachmentImage())
                          .receiptAttachment(applyOrderQo.getReceiptAttachment())
                          .agentCompanyId(applyOrderQo.getAgentCompanyId())
                          .build()
          );
     }

     /**
      * 修改订单状态 确认收货
      * @param orderId
      * @throws Exception
      */
     public void confirmReceipt(Long orderId) throws BusinessException,Exception{
          //获取当前登录用户
          AppletsLoginUser appletsLoginUser = super.getAppletsLoginUser();
          if(appletsLoginUser == null){
               throw new BusinessException(ResultCode.USER_NOT_LOGIN);
          }
          Order order = orderService.findById(orderId);
          if(order == null){
               throw new BusinessException(ResultCode.ORDER_NOT_FOUND);
          }
          Integer status = order.getStatus();
          Integer collectionStatus = order.getCollectionStatus();
          /**
           * 判断订单的上一次的状态是已发货 并且已付款 才可以确认签收
           */
          if(status != OrderEnum.DELIVER_STATUS.code()){
               throw new BusinessException(ResultCode.ORDER_CONFIRM_ERROR);
          }
          orderService.update(
                  Order.builder()
                  .id(orderId)
                  .consignee(appletsLoginUser.getName())
                  .collectionTime(Instant.now().toEpochMilli())
                  .status(OrderEnum.COMPLETE_STATUS.code())
                  .updateTime(Instant.now().toEpochMilli())
                  .build()
          );
     }

     /**
      * 小程序登录用户页面 订单列表查询
      * @param orderListQo
      * @return
      */
     public PageInfo orderList(OrderListQo orderListQo) throws BusinessException,Exception{
          //获取当前登录用户的企业id
          Long companyId = super.getAppletsLoginUser().getCompanyId();
          if(companyId == null){
               throw new BusinessException(ResultCode.USER_NOT_LOGIN);
          }
          String orderNumber = orderListQo.getOrderNumber();
          Integer applyServiceType = orderListQo.getApplyServiceType();
          String applyCompanyType = orderListQo.getApplyCompanyType();
          Integer applyType = orderListQo.getApplyType();
          String taskDeliveryMobile = orderListQo.getTaskDeliveryMobile();
          Integer status = orderListQo.getStatus();
          Condition orderCondition = new Condition(Order.class);
          Example.Criteria criteria = orderCondition.createCriteria();
          criteria.andEqualTo("isDeleted",OrderEnum.NOT_DELETE.code());
          criteria.andCondition("(company_id ="+companyId+" or agent_company_id = "+companyId+")");
//          criteria.andEqualTo("companyId",companyId);
//          criteria.orEqualTo("agentCompanyId",companyId);
          if(StringUtil.isNotEmpty(orderNumber)){
               criteria.andLike("orderNumber","%"+orderNumber+"%");
          }
          if(StringUtil.isNotEmpty(taskDeliveryMobile)){
               criteria.andLike("taskDeliveryMobile","%"+taskDeliveryMobile+"%");
          }
          if(applyServiceType != null){
               criteria.andEqualTo("applyServiceType",applyServiceType);
          }
          if(StringUtil.isNotEmpty(applyCompanyType)){
               criteria.andEqualTo("applyCompanyType",applyCompanyType);
          }
          if(applyType != null){
               criteria.andEqualTo("applyType",applyType);
          }
          if(status != null){
               criteria.andEqualTo("status",status);
          }
          orderCondition.orderBy("applyTime").desc();
          PageHelper.startPage(orderListQo.getPageNum(),orderListQo.getPageSize());
          List<Order> orderList = orderService.findByCondition(orderCondition);
          PageInfo orderPageInfo = new PageInfo<>(orderList);
          //返回自定义的数据集合
          List<OrderListVo> resultList = orderList.stream().map(OrderListVo::new).collect(Collectors.toList());
          //获取企业名称
          Company company = companyService.findById(companyId);
          resultList.stream().forEach(orderListVo -> {
               orderListVo.setCompanyName(company == null ? "" : company.getName());
          });
          //把自定义的集合放入分页对象中
          orderPageInfo.setList(resultList);
          return orderPageInfo;
     }

     /**
      * 订单审核
      * @param auditOrderQo
      * @throws BusinessException
      * @throws Exception
      */
     public void auditOrder(AuditOrderQo auditOrderQo) throws BusinessException,Exception{
          Long id = auditOrderQo.getId();
          Order order = orderService.findById(id);
          if(order == null){
               throw new BusinessException(ResultCode.DATA_NOT_FOUND);
          }
          //订单收款状态
          Integer collectionStatus = order.getCollectionStatus();
          //修改之前的状态
          Integer beforeStatus = order.getStatus();
          //修改之后的状态
          Integer afterStatus = auditOrderQo.getStatus();
          //校验要修改的状态是否合法
          if(!validataStatus(beforeStatus,afterStatus,collectionStatus)){
               throw new BusinessException(ResultCode.ORDER_STATUS_ERROR);
          }
          orderService.update(
                  Order.builder()
                  .id(id)
                  .status(afterStatus)
                  .updateTime(Instant.now().toEpochMilli())
                  .unitPrice(StringUtil.isEmpty(auditOrderQo.getUnitPrice()) ? null : new BigDecimal(auditOrderQo.getUnitPrice()).setScale(4))
                  .totalPrice(StringUtil.isEmpty(auditOrderQo.getTotalPrice()) ? null : new BigDecimal(auditOrderQo.getTotalPrice()).setScale(4))
                  .startNumber(auditOrderQo.getStartNumber())
                  .endNumber(auditOrderQo.getEndNumber())
                  .repairNumber(auditOrderQo.getRepairNumber() == null ? 0 : auditOrderQo.getRepairNumber())
                  .collectionType(auditOrderQo.getCollectionType())
                  .logisticsNum(auditOrderQo.getLogisticsNum()) //物流单号
                  .build()
          );
     }

     /**
      * 订单状态校验
      * @param beforeStatus
      * @param afterStatus
      * @param collectionStatus
      * @return 是否可以修改
      */
     private boolean validataStatus(Integer beforeStatus,Integer afterStatus,Integer collectionStatus){
          //只能拒绝待审核的状态订单
          if(afterStatus == OrderEnum.REJECT_STATUS.code() && beforeStatus == OrderEnum.INIT_STATUS.code()){
               return true;
          }
          //待审核状态 只能修改为待发货状态
          if(beforeStatus == OrderEnum.INIT_STATUS.code() && afterStatus == OrderEnum.PROCESS_STATUS.code()){
               return true;
          }
          //待发货状态 只能修改为已发货状态
          if(beforeStatus == OrderEnum.PROCESS_STATUS.code() && afterStatus == OrderEnum.DELIVER_STATUS.code()){
               return true;
          }
          //已发货状态 只能修改为已签收状态
          if(beforeStatus == OrderEnum.DELIVER_STATUS.code() && afterStatus == OrderEnum.COMPLETE_STATUS.code()){
               return true;
          }

          return false;
     }

     /**
      * 添加订单备注
      * @param addOrderRemarkQo
      * @throws BusinessException
      * @throws Exception
      */
     public void addOrderRemark(AddOrderRemarkQo addOrderRemarkQo) throws BusinessException,Exception{
          Long id = addOrderRemarkQo.getId();
          Order order = orderService.findById(id);
          if(order == null){
               throw new BusinessException(ResultCode.DATA_NOT_FOUND);
          }
          order.setRemark(addOrderRemarkQo.getRemark());
          order.setUpdateTime(Instant.now().toEpochMilli());
          orderService.update(
                  Order.builder()
                  .id(id).remark(addOrderRemarkQo.getRemark())
                  .updateTime(Instant.now().toEpochMilli())
                  .build()
          );
     }

     /**
      * 后台管理 获取标签订单列表
      * @param orderListQo
      * @return
      * @throws Exception
      */
     public PageInfo orderListAdmin(OrderListQo orderListQo) throws Exception{
          String orderNumber = orderListQo.getOrderNumber();
          Integer applyServiceType = orderListQo.getApplyServiceType();
          String applyCompanyType = orderListQo.getApplyCompanyType();
          Integer applyType = orderListQo.getApplyType();
          String taskDeliveryMobile = orderListQo.getTaskDeliveryMobile();
          Integer status = orderListQo.getStatus();
          Long companyId = orderListQo.getCompanyId();
          Long startTime = orderListQo.getStartTime();
          Long endTime = orderListQo.getEndTime();
          Condition orderCondition = new Condition(Order.class);
          Example.Criteria criteria = orderCondition.createCriteria();
          criteria.andEqualTo("isDeleted",OrderEnum.NOT_DELETE.code());
          if(StringUtil.isNotEmpty(orderNumber)){
               criteria.andLike("orderNumber","%"+orderNumber+"%");
          }
          if(StringUtil.isNotEmpty(taskDeliveryMobile)){
               criteria.andLike("taskDeliveryMobile","%"+taskDeliveryMobile+"%");
          }
          if(applyServiceType != null){
               criteria.andEqualTo("applyServiceType",applyServiceType);
          }
          if(StringUtil.isNotEmpty(applyCompanyType)){
               criteria.andEqualTo("applyCompanyType",applyCompanyType);
          }
          if(applyType != null){
               criteria.andEqualTo("applyType",applyType);
          }
          if(status != null){
               criteria.andEqualTo("status",status);
          }
          if(companyId != null){
               criteria.andEqualTo("companyId",companyId);
          }
          if(startTime != null && endTime != null){
               criteria.andGreaterThanOrEqualTo("createTime",startTime);
               criteria.andLessThanOrEqualTo("createTime",endTime);
          }
          if(startTime != null && endTime == null){
               criteria.andGreaterThanOrEqualTo("createTime",startTime);
               criteria.andLessThanOrEqualTo("createTime",Instant.now().toEpochMilli());
          }
          if(startTime == null && endTime != null){
               criteria.andLessThanOrEqualTo("createTime",endTime);
          }
          orderCondition.orderBy("applyTime").desc();
          PageHelper.startPage(orderListQo.getPageNum(),orderListQo.getPageSize());
          List<Order> orderList = orderService.findByCondition(orderCondition);
          PageInfo orderPageInfo = new PageInfo<>(orderList);
          //返回自定义的数据集合
          List<OrderListVo> resultList = orderList.stream().map(OrderListVo::new).collect(Collectors.toList());
          //设置企业名称
          resultList.stream().forEach(orderListVo -> {
               Company company = companyService.findById(orderListVo.getCompanyId());
               orderListVo.setCompanyName(company == null ? "" : company.getName());
          });
          //把自定义的集合放入分页对象中
          orderPageInfo.setList(resultList);
          return orderPageInfo;
     }

     /**
      * 根据条件获取所有订单  不分页
      * @param orderListQo
      * @return
      * @throws Exception
      */
     public List<OrderListVo> orderAllList(OrderListQo orderListQo) throws Exception{
          String orderNumber = orderListQo.getOrderNumber();
          Integer applyServiceType = orderListQo.getApplyServiceType();
          String applyCompanyType = orderListQo.getApplyCompanyType();
          Integer applyType = orderListQo.getApplyType();
          String taskDeliveryMobile = orderListQo.getTaskDeliveryMobile();
          Integer status = orderListQo.getStatus();
          Long companyId = orderListQo.getCompanyId();
          Long startTime = orderListQo.getStartTime();
          Long endTime = orderListQo.getEndTime();
          Condition orderCondition = new Condition(Order.class);
          Example.Criteria criteria = orderCondition.createCriteria();
          criteria.andEqualTo("isDeleted",OrderEnum.NOT_DELETE.code());
          if(StringUtil.isNotEmpty(orderNumber)){
               criteria.andLike("orderNumber","%"+orderNumber+"%");
          }
          if(StringUtil.isNotEmpty(taskDeliveryMobile)){
               criteria.andLike("taskDeliveryMobile","%"+taskDeliveryMobile+"%");
          }
          if(applyServiceType != null){
               criteria.andEqualTo("applyServiceType",applyServiceType);
          }
          if(StringUtil.isNotEmpty(applyCompanyType)){
               criteria.andEqualTo("applyCompanyType",applyCompanyType);
          }
          if(applyType != null){
               criteria.andEqualTo("applyType",applyType);
          }
          if(status != null){
               criteria.andEqualTo("status",status);
          }
          if(companyId != null){
               criteria.andEqualTo("companyId",companyId);
          }
          if(startTime != null && endTime != null){
               criteria.andGreaterThanOrEqualTo("createTime",startTime);
               criteria.andLessThanOrEqualTo("createTime",endTime);
          }
          if(startTime != null && endTime == null){
               criteria.andGreaterThanOrEqualTo("createTime",startTime);
               criteria.andLessThanOrEqualTo("createTime",Instant.now().toEpochMilli());
          }
          if(startTime == null && endTime != null){
               criteria.andLessThanOrEqualTo("createTime",endTime);
          }
          orderCondition.orderBy("applyTime").desc();
          List<Order> orderList = orderService.findByCondition(orderCondition);
          //返回自定义的数据集合
          List<OrderListVo> resultList = orderList.stream().map(OrderListVo::new).collect(Collectors.toList());
          //设置企业名称
          resultList.stream().forEach(orderListVo -> {
               Company company = companyService.findById(orderListVo.getCompanyId());
               orderListVo.setCompanyName(company == null ? "" : company.getName());
          });
          return resultList;
     }

     /**
      * 订单确认收款 只能对待发货的订单进行收款
      * @param confirmReceiptQo
      */
     public void confirmCollection(ConfirmReceiptQo confirmReceiptQo) throws BusinessException,Exception{
          //获取当前登录用户
          AdminLoginUser adminLoginUser = super.getAdminLoginUser();
          if(adminLoginUser == null){
               throw new BusinessException(ResultCode.USER_NOT_LOGIN);
          }
          Long orderId = confirmReceiptQo.getOrderId();
          Order order = orderService.findById(orderId);
          if(order == null){
               throw new BusinessException(ResultCode.DATA_NOT_FOUND);
          }
          Integer status = order.getStatus();
          //订单不是审核通过之后的待发货状态， 不能确认收款
          /*if(status != OrderEnum.PROCESS_STATUS.code()){
               throw new BusinessException(ResultCode.ORDER_COLLECTION_ERROR);
          }*/
          orderService.update(Order.builder()
                  .id(orderId)
                  .collectionId(adminLoginUser.getId())
                  .collection(adminLoginUser.getName())
                  .collectionTime(Instant.now().toEpochMilli())
                  .collectionStatus(OrderEnum.RECEIVED_STATUS.code())
                  .updateTime(Instant.now().toEpochMilli())
                  .build()
          );
     }


     /**
      * 获取订单详情
      * @param orderId
      * @return
      * @throws BusinessException
      * @throws Exception
      */
     public OrderListVo orderDetail(Long orderId) throws BusinessException,Exception{
          //获取当前登录用户
          AdminLoginUser adminLoginUser = super.getAdminLoginUser();
          if(adminLoginUser == null){
               throw new BusinessException(ResultCode.USER_NOT_LOGIN);
          }
          Order order = orderService.findById(orderId);
          if(order == null){
               throw new BusinessException(ResultCode.DATA_NOT_FOUND);
          }
          OrderListVo orderListVo = new OrderListVo(order);
          //获取企业名称
          Company company = companyService.findById(orderListVo.getCompanyId());
          orderListVo.setCompanyName(company == null ? "" : company.getName());
          //获取代理企业名称
          Company agentCompany = companyService.findById(orderListVo.getAgentCompanyId());
          orderListVo.setAgentCompanyName(agentCompany == null ? "" : agentCompany.getName());
          //查询订单明细集合
          Condition condition = new Condition(OrderDetail.class);
          Example.Criteria criteria = condition.createCriteria();
          criteria.andEqualTo("orderId",orderId);
          criteria.andEqualTo("isDeleted", OrderDetailEnum.NOT_DELETE.code());
          condition.orderBy("createTime").desc();
          List<OrderDetail> orderDetailList = orderDetailService.findByCondition(condition);
          if(!orderDetailList.isEmpty()){
               List<OrderDetailVo> orderDetailVoList = orderDetailList.stream().map(OrderDetailVo::new).collect(Collectors.toList());
               orderListVo.setOrderDetailVoList(orderDetailVoList);
          }
          return orderListVo;
     }

     /**
      * 修改订单码段
      * @param editOrderQo
      */
     public void editOrder(EditOrderQo editOrderQo) throws Exception,BusinessException{
          Long id = editOrderQo.getId();
          Order order = orderService.findById(id);
          if(order == null){
               throw new BusinessException(ResultCode.DATA_NOT_FOUND);
          }
          orderService.update(
                  Order.builder()
                          .id(id)
                          .updateTime(Instant.now().toEpochMilli())
                          .startNumber(editOrderQo.getStartNumber())
                          .endNumber(editOrderQo.getEndNumber())
                          .repairNumber(editOrderQo.getRepairNumber() == null ? 0 : editOrderQo.getRepairNumber())
                          .receiptAttachment(editOrderQo.getReceiptAttachment())
                          .build()
          );
     }

     /**
      * 订单废弃
      * @param orderId
      * @param remark
      */
     public void discardOrder(Long orderId,String remark) throws Exception,BusinessException{
          Order order = orderService.findById(orderId);
          if(order == null){
               throw new BusinessException(ResultCode.DATA_NOT_FOUND);
          }
          //已经废弃的订单不允许重复废弃
          if(order.getStatus() == OrderEnum.DISCARD_STATUS.code()){
               throw new BusinessException(ResultCode.ORDER_DISCARD_STATUS);
          }
          //已收款订单不允许废弃
          if(order.getCollectionStatus() == OrderEnum.RECEIVED_STATUS.code()){
               throw new BusinessException(ResultCode.ORDER_NOT_DELETED);
          }
          order.setRemark(remark);
          order.setStatus(OrderEnum.DISCARD_STATUS.code());
          order.setUpdateTime(Instant.now().toEpochMilli());
          orderService.update(order);
     }
}
